//
//  AuthenticationToken.swift
//  uwantgoeasy
//
//  Created by 冯传宝 on 12/11/15.
//  Copyright © 2015 uwantsoft. All rights reserved.
//

import Foundation
class AuthenticationToken : ClientMessage{
    private var appkey: String=""
    private var userId: String=""
    private var username: String=""
    private var connectDurationMills: UInt=0
    private var device:Device = Device()
    
    init(sid:String, appkey:String, userId:String, username:String, connectDurationMills:UInt){
        super.init(sid: sid)
        self.appkey = appkey
        self.userId = userId
        self.username = username
        self.connectDurationMills = connectDurationMills
    }
    
    override func typeCode() -> Int {
        return 1
    }
    
    override func jsonAsString()->String{
        let deviceDict = Mirror(reflecting: device).toDictionary()
        var dict = Dictionary<String,AnyObject>()
        dict.updateValue(appkey, forKey: "appkey")
        dict.updateValue(userId, forKey: "userId")
        dict.updateValue(username, forKey: "username")
        dict.updateValue(connectDurationMills, forKey: "connectDurationMills")
        dict.updateValue(sid, forKey: "sid")
        dict.updateValue(executorNumber, forKey: "executorNumber")
        dict.updateValue(deviceDict, forKey: "device")
        
        return GoEasyJsonUtils.dictAsJsonString(dict)
    }
}